const Model = require("../models/Model");
module.exports = class AlarmManager {
  /**
   * 增加一个model
   * @param {*} ModelObj
   * @returns
   */
  static async addModel(ModelObj) {
    const result = await Model.create(ModelObj);
    return result.toJSON();
  }
  /**
   * 删除一个model
   * @param {*} modelId
   */
  static async deleteModel(modelId) {
    const result = await Model.destroy({
      where: {
        id: modelId,
      },
    });
  }
  /**
   * 更新model
   * @param {*} modelId
   * @param {*} ModelObj
   */
  static async updateModel(modelId, ModelObj) {
    await Model.update(ModelObj, {
      where: {
        id: modelId,
      },
    });
    const result = await Model.findOne({
      where: {
        id: modelId,
      },
    });
    return result;
  }

  /**
   * 查询所有的model
   * @returns
   */
  static async getAllModel() {
    const result = await Model.findAll();
    return JSON.parse(JSON.stringify(result));
  }
};
